package xps.and.uudaijia.userclient.data.net;


import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import xps.and.uudaijia.userclient.data.serviceapi.PayApi;
import xps.and.uudaijia.userclient.data.serviceapi.UserApi;

public abstract class RetrofitUtils {

    //线下
    //public static final String ROOT = "http://60.205.149.135:8080/v1";
    //线上
    public static final String ROOT = "http://api.xn--uu-df3cl18z.com/v1";
    //不做修改
    public static final String ROOTHuo = "http://60.205.149.135/v1";
    
    protected static UserApi userApi = null;
    protected static OkHttpClient okHttpClient = OkhttpUtils.getOkHttpClient();
    protected static PayApi payApi = null;

    protected static UserApi getUserApi() {
        if (null == userApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOT + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            userApi = mRetrofit.create(UserApi.class);
        }
        return userApi;
    }

    protected static PayApi getPayApi() {
        if (null == payApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOT + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            payApi = mRetrofit.create(PayApi.class);
        }
        return payApi;
    }

    protected static UserApi getPayApiHuo() {
        if (null == userApi) {
            Retrofit mRetrofit = new Retrofit.Builder()
                    .baseUrl(ROOTHuo + "/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(okHttpClient)
                    .build();
            userApi = mRetrofit.create(UserApi.class);
        }
        return userApi;
    }
}